package cn.ilongfei.web;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ilongfei.job.MyJob;
import cn.ilongfei.job.QuartzManager;
/**
 * @author liukz
 *访问地址http://localhost:8030/mvcframe/job/startQuartz
 */
@Controller
@RequestMapping(value = "/job")
public class JobController {
	private static Logger logger = LoggerFactory
			.getLogger(JobController.class);
	//这个bean在spring中配置，可以直接注入
	    @Resource
	    private QuartzManager quartzManager;
	
	    @RequestMapping(value = "startQuartz", method = {RequestMethod.GET})
	    @ResponseBody
	    public String testQuartz(String quartzTime) throws Exception{
	    	quartzTime = "2018-12-07 14:49:00";
	        logger.info("===========开始执行调度=========时间为 " + quartzTime);
	         String cronStr = quartzManager.transCron(quartzTime);
	       // logger.info("======cron表达式========" + cronStr);
	        //quartzManager.addJob("test", "test", "test", "test", MyJob.class, cronStr);  
	        quartzManager.addJob("test", "test", "test", "test", MyJob.class, "0/10 * * * * ?"); 
	        
	        //quartzManager.addJob("test", "test", "test", "test", MyJob.class, "0 50 10 * * ?");  
	        //quartzManager.modifyJobTime("test", "test", "test", "test", "0 50 10 * * ?");    
	        //quartzManager.removeJob("test", "test", "test", "test");    
	        //quartzManager.shutdownJobs();
	        return "success";
	    }
	
	    @RequestMapping(value = "stopQuartz", method = {RequestMethod.GET})
	    @ResponseBody
	    public String shutDownQuartz() throws Exception{
	        logger.info("===========关闭调度test==================");
	        quartzManager.removeJob("test", "test", "test", "test");  
	        return "关闭成功";
	    }
}

